Use QueryPerformanceCounter for babl_ticks on Win32
authorDaniel Sabo <DanielSabo@gmail.com>
Sat, 6 Apr 2013 03:11:03 +0000 (20:11 -0700)
committerDaniel Sabo <DanielSabo@gmail.com>
Sat, 6 Apr 2013 09:24:32 +0000 (02:24 -0700)
babl/babl-util.c

index 40ddfa2c2bc03c88e5aed08ee4cf257ec553b226..92977ac8ca7bda662ee704b8754451a3c12ca6ac 100644 (file)
 #include <math.h>
 #include "babl-internal.h"
 
+#ifdef __WIN32__
+#include <windows.h>
+#else
 #include <sys/time.h>
 #include <time.h>
+#endif
 
+#ifdef __WIN32__
+static LARGE_INTEGER start_time;
+static LARGE_INTEGER timer_freq;
+
+static void
+init_ticks (void)
+{
+  static int done = 0;
+
+  if (done)
+    return;
+  done = 1;
+
+  QueryPerformanceCounter(&start_time);
+  QueryPerformanceFrequency(&timer_freq);
+}
+
+long
+babl_ticks (void)
+{
+  LARGE_INTEGER end_time;
+
+  init_ticks ();
+
+  QueryPerformanceCounter(&end_time);
+  return (end_time.QuadPart - start_time.QuadPart) * (1000000.0 / timer_freq.QuadPart);
+}
+#else
 static struct timeval start_time;
 
 #define usecs(time)    ((time.tv_sec - start_time.tv_sec) * 1000000 + time.tv_usec)
@@ -46,6 +78,7 @@ babl_ticks (void)
   gettimeofday (&measure_time, NULL);
   return usecs (measure_time) - usecs (start_time);
 }
+#endif
 
 long
 babl_process_cost (long ticks_start,